/*
* @Author: Carrix
* @Date:   2020-01-14 15:04:37
* @Last Modified by:   Carrix
* @Last Modified time: 2020-01-14 21:14:24
*/
import React, { Component } from 'react'

import Simditor from 'simditor'
import $ from 'jquery'
import 'simditor/styles/simditor.css'

class RichEditor extends Component{
	constructor(props){
		super(props)
		this.toolbar = [
			'title',
			'bold',
			'italic',
			'underline',
			'strikethrough',
			'fontScale',
			'color',
			'ol',
			'ul',
			'blockquote',
			'code',
			'table',
			'link',
			'image',
			'hr',
			'indent',
			'outdent',
			'alignment',		
		]
		$.ajaxSetup({
			xhrFields:{
				withCredentials:true
			}
		})
	}
	componentDidMount(){
		this.editor = new Simditor({
			textarea:this.textarea,
			toolbar:this.toolbar,
			upload:{
				url:this.props.url,
				fileKey:'upload'
			}
		})
		this.editor.on('valuechanged',()=>{
			this.props.getValues(this.editor.getValue())
		})
	}

	render(){
		return(
			<textarea ref={(textarea)=>{this.textarea=textarea}}></textarea>
		)
	}
}
export default RichEditor